package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;

/**
 * @author: zen
 * @date: 2020/4/15
 * @Title: MyFileter
 * @Description:
 */
@WebFilter(filterName = "MyFilter",
            urlPatterns = "/*",
            initParams = @WebInitParam(name = "encoding", value = "UTF-8"))
public class MyFileter implements Filter {

    private String characterEncoding;
    FilterConfig fc;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // 获取FilterConfig对象
        this.fc = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        // 输出参数信息
        characterEncoding = fc.getInitParameter("encoding");
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
